﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="XompareCliParser.cs" company="" />
// <summary>
//   Defines the CLAP parser for a command line approach to the utility.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Xompare
{
    using System;
    using System.Windows.Forms;

    using CLAP;

    using Utilities;

    using Xompare.Helpers;

    /// <summary>
    /// Defines the CLAP parser for a command line approach to the utility.
    /// NOTE: The verbs assume the UI is already in place and ready.
    /// </summary>
    public class XompareCliParser
    {
        [Empty, Help]
        public static void UpdateHelpString(string helpMessage)
        {
            Controller.CliHelpMessage = helpMessage;
        }

        [Verb(Aliases = "files", Description = "Compares given XML files")]
        public static void FileDiff(
            [Parameter(Aliases = "ofn", Description = "The original XML file name")] string originalFileName = null,
            [Parameter(Aliases = "tfn", Description = "The target XML file name")] string targetFileName = null,
            [Parameter(Aliases = "ol", Description = "A label describing the original XML file")] string labelForOriginal = null,
            [Parameter(Aliases = "tl", Description = "A label describing the target XML file")] string labelForTarget = null)
        {
            Controller.CreateFileDiffTab(
                () =>
                {
                    if (originalFileName == null)
                    {
                        var fileDialog = new OpenFileDialog { Title = "Choose the original XML file" };

                        fileDialog.ShowDialog();
                        originalFileName = fileDialog.FileName;
                    }

                    return new NameAndLabel(originalFileName, labelForOriginal);
                },
                () =>
                {
                    if (targetFileName == null)
                    {
                        var fileDialog = new OpenFileDialog { Title = "Choose the target XML file" };

                        fileDialog.ShowDialog();
                        targetFileName = fileDialog.FileName;
                    }

                    return new NameAndLabel(targetFileName, labelForTarget);
                });
        }
    }
}
